;Copyright 2010, 2011  Jean Champemont jean.champemont@gmail.com

;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License as
;published by the Free Software Foundation; either version 2 of 
;the License, or (at your option) any later version.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program.  If not, see <http://www.gnu.org/licenses/>.

global loader
extern kmain
	bits 	32						;Tell nasm we want 32 bits code
MAGIC	equ	0x1BADB002					;Magic number required by multiboot spec.
FLAG	equ	0x00010000					;Flags required by multiboot spec.
CHECKS	equ	-(MAGIC + FLAG)					;Checksum required by multiboot spec.
LOADB	equ	0x00100000					;Load base

STACKSZ equ	0x4000						;stack space : 16k

section .text

multiboot_header:
	dd	MAGIC
	dd	FLAG
	dd 	CHECKS
	dd	LOADB + multiboot_header			;Memory adress multiboot header
	dd	LOADB						;Where to Load kinit
	dd	0						;load_end_addr not necessary
	dd	0						;bss_end_addr not necessary
	dd	LOADB + loader					;Jump address
loader:
	mov	esp, stack+STACKSZ				;setup stack
	push	eax						;pass multiboot magic number to kmain
	push	ebx						;pass multiboot info struct to kmain
	call	kmain

	cli
hang:
	hlt
	jmp	hang

section .bss
	align	4
stack:
	resb	STACKSZ						;reserver 16k stack
